﻿using HoloJson.Mini;
using HoloJson.Mini.Parser;
using HoloJson.Mini.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;


namespace HoloJson.MiniDriver
{
    internal class ParserDemoDriver
    {

        private LiteJsonParser jsonParser;

        internal ParserDemoDriver()
        {
            jsonParser = new HoloJsonMiniParser();
        }
        
        internal async Task RunTestParse(StorageFile jsonFile)
        {
            try {

                //var jsonStr = "{\"a\":20}";
                //object node = jsonParser.Parse(jsonStr);

                var jsonStr = await FileIO.ReadTextAsync(jsonFile);
                object node = await jsonParser.ParseAsync(jsonStr);

                var jsonObject = node as IDictionary<string, object>;
                var jsonArray = node as IList<object>;

                System.Diagnostics.Debug.WriteLine("Parsed: node = " + node.ToString());
                System.Diagnostics.Debug.WriteLine("Parsed: jsonObject = " + jsonObject.ToDebugString());
                System.Diagnostics.Debug.WriteLine("Parsed: jsonArray = " + jsonArray.ToDebugString<string, object>());


            } catch(Exception ex) {
                System.Diagnostics.Debug.WriteLine("Parse failed.", ex);
            }

        }
    }

}
